package action;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.json.JSONArray;


import serive.logservie;


import com.opensymphony.xwork2.ActionSupport;

import dao.hive.Connect;

public class LogAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	


	 public String initColumn3D(){
         try{
                
                 String tablename="log";
                 String sql_ref="getkeylog";
                 Map<String, Integer> resultMap= logservie.getKeyCountSort(tablename,sql_ref,Connect.GetMysqllocal());
                 
                 HttpServletResponse response = ServletActionContext.getResponse();
                 response.setCharacterEncoding("utf-8");
                 response.setContentType("text/xml;charset=utf-8");
                 response.setHeader("cache-control", "no-cache");
                 response.setHeader("pragma", "no-cache");
                 response.setHeader("expires", "0");
                 PrintWriter out = response.getWriter();
                 String xml = "";
                 StringBuffer xmlBuffer = new StringBuffer();
                 /**numberPrefix='$' 代表值前缀为$符 
                    *        ￥:'%A5'
                    *        %:'%25'
                    *        '(单引号):'&apos;'
                    *        &:'&'
                    *numberSuffix='%25' 代表后缀为%
                    *
                    *下钻：
                    *1:普通超链接 link='http://www.sina.com'
                    *2:新窗口超链接 link='n-http://www.126.com'
                    *3:javaScript链接 link=\"javascript:myJs('一月,462')\"
                    *注意：在链接中?&都要先编码 在javascript中使用escape()编码 在服务器端使用 java.net.URLEncoder.encode();
                    */   
                 xmlBuffer.append("<graph unescapeLink='0' chartTopPadding='30' caption='搜狗搜索热词排行榜' baseFontSize='14' palette='10' xAxisName='搜索热词' yAxisName='搜索数量' decimalPrecision='0' formatNumberScale='0'>");
                 int length=resultMap.size();
                 String[] color={"AFD8F8","F6BD0F","8BBA00","3183DD","008E8E","8E468E","008ED6","9D080D","A186BE","D64646","B3AA00","588526","322122","442332","E12332"};
                 for(int i=0;i<length;i++)
                 {
                	 String key=(String) resultMap.keySet().toArray()[i];
                	 xmlBuffer.append("<set name='"+key+"' value='"+resultMap.get(key)+"' color='"+color[i%15]+"' link='sogoukeyword.jsp'/>");
                 }
                 xmlBuffer.append("</graph>");
                 xml = xmlBuffer.toString();
                // System.out.println(xml);
                 out.println("<?xml version='1.0' encoding='UTF-8'?>");
                 out.println(xml);
                 out.flush();
                 out.close();
         }catch(Exception e){
                 e.printStackTrace();
         }
         
         return null;
 }
	 public String keyword()
	 {
		try {
			long time =logservie.keyword();
			System.out.println(time);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return SUCCESS;
		 
	 }
	 public String dns()
	 {
		
		return SUCCESS;
		 
	 }
	 public String person()
	 {
		
		return SUCCESS;
		 
	 }
	 
}
